package org.apache.commons.httpclient.cookie;

import java.util.Collection;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HeaderElement;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.util.DateParseException;
import org.apache.commons.httpclient.util.DateUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class CookieSpecBase
  implements CookieSpec
{
  protected static final Log LOG;
  static Class class$org$apache$commons$httpclient$cookie$CookieSpec;
  private Collection datepatterns = null;

  static
  {
    Class localClass;
    if (class$org$apache$commons$httpclient$cookie$CookieSpec == null)
    {
      localClass = class$("org.apache.commons.httpclient.cookie.CookieSpec");
      class$org$apache$commons$httpclient$cookie$CookieSpec = localClass;
    }
    while (true)
    {
      LOG = LogFactory.getLog(localClass);
      return;
      localClass = class$org$apache$commons$httpclient$cookie$CookieSpec;
    }
  }

  private static void addInPathOrder(List paramList, Cookie paramCookie)
  {
    for (int i = 0; ; ++i)
    {
      if ((i < paramList.size()) && (paramCookie.compare(paramCookie, (Cookie)paramList.get(i)) <= 0))
        continue;
      paramList.add(i, paramCookie);
      return;
    }
  }

  static Class class$(String paramString)
  {
    try
    {
      Class localClass = Class.forName(paramString);
      return localClass;
    }
    catch (ClassNotFoundException localClassNotFoundException)
    {
      throw new NoClassDefFoundError(localClassNotFoundException.getMessage());
    }
  }

  public boolean domainMatch(String paramString1, String paramString2)
  {
    if (paramString1.equals(paramString2));
    for (int i = 1; ; i = 0)
      while (true)
      {
        return i;
        if (!(paramString2.startsWith(".")))
          paramString2 = "." + paramString2;
        if ((!(paramString1.endsWith(paramString2))) && (!(paramString1.equals(paramString2.substring(1)))))
          break;
        i = 1;
      }
  }

  public String formatCookie(Cookie paramCookie)
  {
    LOG.trace("enter CookieSpecBase.formatCookie(Cookie)");
    if (paramCookie == null)
      throw new IllegalArgumentException("Cookie may not be null");
    StringBuffer localStringBuffer = new StringBuffer();
    localStringBuffer.append(paramCookie.getName());
    localStringBuffer.append("=");
    String str = paramCookie.getValue();
    if (str != null)
      localStringBuffer.append(str);
    return localStringBuffer.toString();
  }

  public Header formatCookieHeader(Cookie paramCookie)
  {
    LOG.trace("enter CookieSpecBase.formatCookieHeader(Cookie)");
    return new Header("Cookie", formatCookie(paramCookie));
  }

  public Header formatCookieHeader(Cookie[] paramArrayOfCookie)
  {
    LOG.trace("enter CookieSpecBase.formatCookieHeader(Cookie[])");
    return new Header("Cookie", formatCookies(paramArrayOfCookie));
  }

  public String formatCookies(Cookie[] paramArrayOfCookie)
    throws IllegalArgumentException
  {
    LOG.trace("enter CookieSpecBase.formatCookies(Cookie[])");
    if (paramArrayOfCookie == null)
      throw new IllegalArgumentException("Cookie array may not be null");
    if (paramArrayOfCookie.length == 0)
      throw new IllegalArgumentException("Cookie array may not be empty");
    StringBuffer localStringBuffer = new StringBuffer();
    for (int i = 0; i < paramArrayOfCookie.length; ++i)
    {
      if (i > 0)
        localStringBuffer.append("; ");
      localStringBuffer.append(formatCookie(paramArrayOfCookie[i]));
    }
    return localStringBuffer.toString();
  }

  public Collection getValidDateFormats()
  {
    return this.datepatterns;
  }

  public boolean match(String paramString1, int paramInt, String paramString2, boolean paramBoolean, Cookie paramCookie)
  {
    LOG.trace("enter CookieSpecBase.match(String, int, String, boolean, Cookie");
    if (paramString1 == null)
      throw new IllegalArgumentException("Host of origin may not be null");
    if (paramString1.trim().equals(""))
      throw new IllegalArgumentException("Host of origin may not be blank");
    if (paramInt < 0)
      throw new IllegalArgumentException("Invalid port: " + paramInt);
    if (paramString2 == null)
      throw new IllegalArgumentException("Path of origin may not be null.");
    if (paramCookie == null)
      throw new IllegalArgumentException("Cookie may not be null");
    if (paramString2.trim().equals(""))
      paramString2 = "/";
    String str = paramString1.toLowerCase();
    if (paramCookie.getDomain() == null)
      LOG.warn("Invalid cookie state: domain not specified");
    for (int i = 0; ; i = 0)
      while (true)
      {
        return i;
        if (paramCookie.getPath() == null)
        {
          LOG.warn("Invalid cookie state: path not specified");
          i = 0;
        }
        if (((paramCookie.getExpiryDate() != null) && (!(paramCookie.getExpiryDate().after(new Date())))) || (!(domainMatch(str, paramCookie.getDomain()))) || (!(pathMatch(paramString2, paramCookie.getPath()))) || ((paramCookie.getSecure()) && (!(paramBoolean))))
          break;
        i = 1;
      }
  }

  public Cookie[] match(String paramString1, int paramInt, String paramString2, boolean paramBoolean, Cookie[] paramArrayOfCookie)
  {
    LOG.trace("enter CookieSpecBase.match(String, int, String, boolean, Cookie[])");
    if (paramArrayOfCookie == null);
    LinkedList localLinkedList;
    for (Cookie[] arrayOfCookie = null; ; arrayOfCookie = (Cookie[])(Cookie[])localLinkedList.toArray(new Cookie[localLinkedList.size()]))
    {
      return arrayOfCookie;
      localLinkedList = new LinkedList();
      for (int i = 0; i < paramArrayOfCookie.length; ++i)
      {
        if (!(match(paramString1, paramInt, paramString2, paramBoolean, paramArrayOfCookie[i])))
          continue;
        addInPathOrder(localLinkedList, paramArrayOfCookie[i]);
      }
    }
  }

  public Cookie[] parse(String paramString1, int paramInt, String paramString2, boolean paramBoolean, String paramString3)
    throws MalformedCookieException
  {
    LOG.trace("enter CookieSpecBase.parse(String, port, path, boolean, Header)");
    if (paramString1 == null)
      throw new IllegalArgumentException("Host of origin may not be null");
    if (paramString1.trim().equals(""))
      throw new IllegalArgumentException("Host of origin may not be blank");
    if (paramInt < 0)
      throw new IllegalArgumentException("Invalid port: " + paramInt);
    if (paramString2 == null)
      throw new IllegalArgumentException("Path of origin may not be null.");
    if (paramString3 == null)
      throw new IllegalArgumentException("Header may not be null.");
    if (paramString2.trim().equals(""))
      paramString2 = "/";
    String str1 = paramString1.toLowerCase();
    String str2 = paramString2;
    int i = str2.lastIndexOf("/");
    if (i >= 0)
    {
      if (i == 0)
        i = 1;
      str2 = str2.substring(0, i);
    }
    int j = 0;
    int k = paramString3.toLowerCase().indexOf("expires=");
    int i3;
    int i4;
    if (k != -1)
    {
      i3 = k + "expires=".length();
      i4 = paramString3.indexOf(";", i3);
      if (i4 == -1)
        i4 = paramString3.length();
    }
    try
    {
      DateUtil.parseDate(paramString3.substring(i3, i4), this.datepatterns);
      j = 1;
      HeaderElement[] arrayOfHeaderElement;
      Cookie[] arrayOfCookie;
      if (j != 0)
      {
        arrayOfHeaderElement = new HeaderElement[1];
        arrayOfHeaderElement[0] = new HeaderElement(paramString3.toCharArray());
        arrayOfCookie = new Cookie[arrayOfHeaderElement.length];
      }
      for (int l = 0; l < arrayOfHeaderElement.length; ++l)
      {
        Cookie localCookie;
        while (true)
        {
          HeaderElement localHeaderElement = arrayOfHeaderElement[l];
          try
          {
            localCookie = new Cookie(str1, localHeaderElement.getName(), localHeaderElement.getValue(), str2, null, false);
            NameValuePair[] arrayOfNameValuePair = localHeaderElement.getParameters();
            if (arrayOfNameValuePair == null)
              break label390;
            for (int i1 = 0; ; ++i1)
            {
              int i2 = arrayOfNameValuePair.length;
              if (i1 >= i2)
                break label390;
              parseAttribute(arrayOfNameValuePair[i1], localCookie);
            }
            arrayOfHeaderElement = HeaderElement.parseElements(paramString3.toCharArray());
          }
          catch (IllegalArgumentException localIllegalArgumentException)
          {
            throw new MalformedCookieException(localIllegalArgumentException.getMessage());
          }
        }
        label390: arrayOfCookie[l] = localCookie;
      }
      return arrayOfCookie;
    }
    catch (DateParseException localDateParseException)
    {
    }
  }

  public Cookie[] parse(String paramString1, int paramInt, String paramString2, boolean paramBoolean, Header paramHeader)
    throws MalformedCookieException
  {
    LOG.trace("enter CookieSpecBase.parse(String, port, path, boolean, String)");
    if (paramHeader == null)
      throw new IllegalArgumentException("Header may not be null.");
    return parse(paramString1, paramInt, paramString2, paramBoolean, paramHeader.getValue());
  }

  public void parseAttribute(NameValuePair paramNameValuePair, Cookie paramCookie)
    throws MalformedCookieException
  {
    if (paramNameValuePair == null)
      throw new IllegalArgumentException("Attribute may not be null.");
    if (paramCookie == null)
      throw new IllegalArgumentException("Cookie may not be null.");
    String str1 = paramNameValuePair.getName().toLowerCase();
    String str2 = paramNameValuePair.getValue();
    if (str1.equals("path"))
    {
      if ((str2 == null) || (str2.trim().equals("")))
        str2 = "/";
      paramCookie.setPath(str2);
      paramCookie.setPathAttributeSpecified(true);
    }
    while (true)
    {
      return;
      if (str1.equals("domain"))
      {
        if (str2 == null)
          throw new MalformedCookieException("Missing value for domain attribute");
        if (str2.trim().equals(""))
          throw new MalformedCookieException("Blank value for domain attribute");
        paramCookie.setDomain(str2);
        paramCookie.setDomainAttributeSpecified(true);
      }
      if (str1.equals("max-age"))
      {
        if (str2 == null)
          throw new MalformedCookieException("Missing value for max-age attribute");
        try
        {
          int i = Integer.parseInt(str2);
          paramCookie.setExpiryDate(new Date(System.currentTimeMillis() + 1000L * i));
        }
        catch (NumberFormatException localNumberFormatException)
        {
          throw new MalformedCookieException("Invalid max-age attribute: " + localNumberFormatException.getMessage());
        }
      }
      if (str1.equals("secure"))
        paramCookie.setSecure(true);
      if (str1.equals("comment"))
        paramCookie.setComment(str2);
      if (str1.equals("expires"))
      {
        if (str2 == null)
          throw new MalformedCookieException("Missing value for expires attribute");
        try
        {
          paramCookie.setExpiryDate(DateUtil.parseDate(str2, this.datepatterns));
        }
        catch (DateParseException localDateParseException)
        {
          LOG.debug("Error parsing cookie date", localDateParseException);
          throw new MalformedCookieException("Unable to parse expiration date parameter: " + str2);
        }
      }
      if (!(LOG.isDebugEnabled()))
        continue;
      LOG.debug("Unrecognized cookie attribute: " + paramNameValuePair.toString());
    }
  }

  public boolean pathMatch(String paramString1, String paramString2)
  {
    boolean bool = paramString1.startsWith(paramString2);
    if ((bool) && (paramString1.length() != paramString2.length()) && (!(paramString2.endsWith("/"))))
      if (paramString1.charAt(paramString2.length()) != CookieSpec.PATH_DELIM_CHAR)
        break label48;
    label48: for (bool = true; ; bool = false)
      return bool;
  }

  public void setValidDateFormats(Collection paramCollection)
  {
    this.datepatterns = paramCollection;
  }

  public void validate(String paramString1, int paramInt, String paramString2, boolean paramBoolean, Cookie paramCookie)
    throws MalformedCookieException
  {
    LOG.trace("enter CookieSpecBase.validate(String, port, path, boolean, Cookie)");
    if (paramString1 == null)
      throw new IllegalArgumentException("Host of origin may not be null");
    if (paramString1.trim().equals(""))
      throw new IllegalArgumentException("Host of origin may not be blank");
    if (paramInt < 0)
      throw new IllegalArgumentException("Invalid port: " + paramInt);
    if (paramString2 == null)
      throw new IllegalArgumentException("Path of origin may not be null.");
    if (paramString2.trim().equals(""))
      paramString2 = "/";
    String str1 = paramString1.toLowerCase();
    if (paramCookie.getVersion() < 0)
      throw new MalformedCookieException("Illegal version number " + paramCookie.getValue());
    if (str1.indexOf(".") >= 0)
      if (!(str1.endsWith(paramCookie.getDomain())))
      {
        String str2 = paramCookie.getDomain();
        if (str2.startsWith("."))
          str2 = str2.substring(1, str2.length());
        if (!(str1.equals(str2)))
          throw new MalformedCookieException("Illegal domain attribute \"" + paramCookie.getDomain() + "\". Domain of origin: \"" + str1 + "\"");
      }
    else if (!(str1.equals(paramCookie.getDomain())))
      throw new MalformedCookieException("Illegal domain attribute \"" + paramCookie.getDomain() + "\". Domain of origin: \"" + str1 + "\"");
    if (paramString2.startsWith(paramCookie.getPath()))
      return;
    throw new MalformedCookieException("Illegal path attribute \"" + paramCookie.getPath() + "\". Path of origin: \"" + paramString2 + "\"");
  }
}

/* Location:           E:\Desktop\Android\wordstd\classes_dex2jar.jar
 * Qualified Name:     org.apache.commons.httpclient.cookie.CookieSpecBase
 * JD-Core Version:    0.5.3
 */